package com.zjw.zy.service.net.conver;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zjw.zy.bean.Weather15Day;
import com.zjw.zy.utils.GsonUtils;

import org.json.JSONObject;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Converter;

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/9/27 16:07
 */
public class DayWeatherConverter implements Converter<ResponseBody, Weather15Day> {
    @Nullable
    @Override
    public Weather15Day convert(@NonNull ResponseBody value) {
        try {
            String json = value.string();
            return GsonUtils.fromJson(new JSONObject(json).optString("result"), Weather15Day.class);
        } catch (Exception e) {
            return null;
        }
    }
}
